package org.tarena.dang.dao.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.tarena.dang.dao.productDAO;
import org.tarena.dang.entity.Product;
import org.tarena.dang.util.DbUtil;

public class ProductDAOImpl implements productDAO {

	private String findNewProduct = "select * from d_product order by add_time desc limit ?";
	
	
	@Override
	public List<Product> findNewProduct(int topSize) throws SQLException {
		PreparedStatement pst = DbUtil.openConnection().prepareStatement(findNewProduct);
		pst.setInt(1, topSize);
		ResultSet re = pst.executeQuery();
		List<Product> list = new ArrayList<Product>();
		while(re.next()){
			Product pro = new Product();
			pro.setId(re.getInt("id"));
			pro.setAddTime(re.getLong("add_time"));
			pro.setDangPrice(re.getDouble("dang_price"));
			pro.setDescription(re.getString("description"));
			pro.setFixedPrice(re.getDouble("fixed_price"));
			pro.setHasDelet(re.getInt("has_deleted"));
			pro.setKeyWords(re.getString("keywords"));
			pro.setProductName(re.getString("product_name"));
			pro.setProductPic(re.getString("product_pic"));
			list.add(pro);
		}
		DbUtil.closeConnection();
		return list;
	}


	@Override
	public List<Product> findHotProduct(int topSize) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
